/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>Project: javase2203 - T17
 * <p>Powered by webrx On 2022-08-10 09:37:52
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T17 {
    ReentrantLock lock = new ReentrantLock(true);
    void show(){
        String t = Thread.currentThread().getName();

        while(true){
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            try{
                lock.lock();
                TimeUnit.SECONDS.sleep(1);
                       System.out.println(t);
            }catch(Exception e){
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }
    }
    public static void main(String[] args) {
        var t = new T17();
        new Thread(t::show,"A").start();
        new Thread(t::show,"B").start();
        new Thread(t::show,"C").start();
        new Thread(t::show,"D").start();
    }
}
